package com.situ.day27.reflect;

import java.io.FileInputStream;
import java.io.IOException;
import java.lang.String;
import java.util.Properties;

public class DBFactory {

    public static IDB createDB() throws IOException, ClassNotFoundException, IllegalAccessException, InstantiationException {
        FileInputStream fileInputStream = new FileInputStream("db.properties");
        //FileInputStream fileInputStream = new FileInputStream("D:\\Idea210702\\JavaStudy\\JavaSE\\db.properties");
        Properties properties = new Properties();
        properties.load(fileInputStream);
        String className = properties.getProperty("className");
        System.out.println(className);

        Class clazz = Class.forName(className);
        IDB db = (IDB) clazz.newInstance();
        db.getConnection();

        return db;
    }

    public static IDB createDB1(String name) {
        IDB db = null;
        switch (name) {
            case "MySql":
                db = new MySql();
                break;
            case "Oracle":
                db = new Oracle();
                break;
        }

        return db;
    }
}
